package com.hucheng.user.api.vo;

import com.hucheng.user.api.entity.UserDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-03
 * @Description: 返回界面数据
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserVO implements Serializable {
    private Integer userId;
    private String username;
    private String password;
    private String dateCreated;
    private String dateUpdated;

    public static UserVO buildUserVO(final UserDO userDO) {
        if(userDO==null){
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return new UserVO(userDO.getUserId(),userDO.getUsername(),userDO.getPassword(),
                dateTimeFormatter.format(userDO.getDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(userDO.getDateUpdated().toLocalDateTime()));
    }
}
